package com.dds.soap;

import android.content.Context;
import android.util.Log;

public class SoapUtil {
    /**
     * AbSoapUtil实例.
     */
    public static final boolean isEntry = true; //判断是否用加密的接口
    private static SoapUtil mAbSoapUtil;
    /**
     * 实例话对象.
     */
    private SoapClient mClient = null;

    /**
     * AbSoapUtil构�?�方�?.
     *
     * @param context the context
     */
    private SoapUtil(Context context) {
        super();
        this.mClient = new SoapClient(context);
    }

    /**
     * 单例 获取AbSoapUtil实例.
     *
     * @param context the context
     * @return single instance of AbSoapUtil
     */
    public static SoapUtil getInstance(Context context) {
        if (null == mAbSoapUtil) {

            mAbSoapUtil = new SoapUtil(context);

        }
        return mAbSoapUtil;
    }

    /**
     * Call.
     *
     * @param url        the url
     * @param nameSpace  the name space
     * @param methodName the method name
     * @param params     the params
     * @param listener   the listener
     */
    public void call(String url, String nameSpace, String methodName, SoapParams params, SoapListener listener) {
        Log.e("请求接口", url + "/" + methodName);
        Log.e("请求参数", "=======================");
        for (int i = 0; i < params.getParamsList().size(); i++) {
            Log.e(params.getParamsList().get(i).getName() + ":", params.getParamsList().get(i).getValue());
        }
        Log.e("请求参数", "=======================");
        mClient.call(url, nameSpace, methodName, params, listener);
    }

    public void callEntry(String url, String nameSpace, String methodName, SoapParams params, SoapListener listener, String apiUserName, String apiPwd) {
        Log.e("请求接口", url + "/" + methodName);
        Log.e("请求参数", "=======================");
        for (int i = 0; i < params.getParamsList().size(); i++) {
            Log.e(params.getParamsList().get(i).getName() + ":", params.getParamsList().get(i).getValue());
        }
        Log.e("请求参数", "=======================");
        if (isEntry) {
            mClient.callEntry(url, nameSpace, methodName, params, listener, apiUserName, apiPwd);
        } else {
            mClient.call(url, nameSpace, methodName, params, listener);
        }
    }

    /**
     * 描述：设置连接超时时间(第一次请求前设置).
     *
     * @param timeout 毫秒
     */
    public void setTimeout(int timeout) {
        mClient.setTimeout(timeout);
    }

    /**
     * Sets the dot net.
     *
     * @param dotNet the new dot net
     */
    public void setDotNet(boolean dotNet) {
        mClient.setDotNet(dotNet);
    }
}
